package cnu.ldc.util;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBconnection {
	public static final String URL;
	public static final String USERNAME;
	public static final String PASSWORD;
	public static final String CLASSNAME;
	static {
		Properties po=new Properties();
		try {
			po.load(DBconnection.class.getResourceAsStream("/jdbc.properties"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		URL=po.getProperty("jdbc.url");
		USERNAME=po.getProperty("jdbc.user");
		PASSWORD=po.getProperty("jdbc.password");
		CLASSNAME=po.getProperty("jdbc.className");
		try {
			Class.forName(CLASSNAME);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
public static Connection getConnection(){
	 Connection con = null;
	String url="jdbc:oracle:thin:@localhost:1521:orcl";

	try {
		
		con = DriverManager.getConnection(URL, USERNAME, PASSWORD);
		
	
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return con;
	
}
public static void close(Connection con) {
	if(con!=null) {
		try {
			con.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
}
